﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FortuneHeavenCommon.DataMap;
using System.Data.SqlClient;

namespace FortuneHeavan.Game.DAL
{
    public class AndroidUserInfoDAL : TreasureDBBase
    {
        public List<AndroidUserInfo> GetList(int page, int size, string id)
        {
            if (string.IsNullOrEmpty(id) || id.Trim() == "")
            {
                string sql = @"select * from (
SELECT B.UserID,B.GameID,B.Accounts,C.Score,C.Revenue,C.WinCount,C.LostCount,C.DrawCount, ROW_NUMBER() OVER(ORDER BY B.UserID DESC) as ROW from  QPGameUserDB.dbo.AccountsInfo B 
Left join dbo.GameScoreInfo C ON B.UserID= C.UserID where  B.InsurePass ='7788991100' ) FF
 WHERE FF.ROW BETWEEN  @p0 AND @p1";
                List<AndroidUserInfo> list = Query<AndroidUserInfo>(sql, new SqlParameter("@p0", size * (page - 1) + 1), new SqlParameter("@p1", size * page));
                return list;
            }
            else
            {
                string sql = @"select * from (
SELECT B.UserID,B.GameID,B.Accounts,C.Score,C.Revenue,C.WinCount,C.LostCount,C.DrawCount, ROW_NUMBER() OVER(ORDER BY B.UserID DESC) as ROW from  QPGameUserDB.dbo.AccountsInfo B 
Left join dbo.GameScoreInfo C ON B.UserID= C.UserID WHERE  B.InsurePass ='7788991100' and  B.GameID in (" + id + @") ) FF
 WHERE FF.ROW BETWEEN  @p0 AND @p1";
                List<AndroidUserInfo> list = Query<AndroidUserInfo>(sql, new SqlParameter("@p0", size * (page - 1) + 1), new SqlParameter("@p1", size * page));
                return list;
            }

        }

        public int GetTotalSize(string id)
        {

            if (!string.IsNullOrEmpty(id) && id.Trim() != "")
            {
                string sql = @"SELECT  Count(B.UserID) from  QPGameUserDB.dbo.AccountsInfo B WHERE B.InsurePass ='7788991100'   and  B.GameID in (" + id + @")";
                return RunSQL(sql);
            }
            else
            {
                string sql = @"SELECT Count(B.UserID) from  QPGameUserDB.dbo.AccountsInfo B WHERE B.InsurePass ='7788991100'";
                return RunSQL(sql);
            }

        }
    }
}
